SLOT MACHINE The purse on the right shows how much money the player has to gamble with. To start a game put some money in the machine by clicking on either a £ coin or a 10p piece. One credit (a game) costs 10p. The credit light at the top of the machine shows how many games are left. To start the reels rolling click on the green START button. A reel can be prevented from rolling by pressing the associated HOLD button. This option is only available at random times during the game. When three types of fruit line up as shown on the chart the appropriate amount is added to the bank. If two out of the three fruits line up then half the points are awarded. For every £1 you win one coin on the treasure trial lights up. After every game, while there is money in the bank, the red COLLECT button flashes. When this button is pressed all the money in the bank is put into the purse and the treasure trail lights go out. When the player's game credits have run out they must use more from their purse. Alternatively they can play using money from their bank by pressing the green flashing START button instead of COLLECT. Winning combinations Three Cherries 10p Two Cherries 5p Three Melons 20p Two Melons 10p Three Lemons 30p Two Lemons 15p Three Plums 40p Two Plums 20p Three Pears 50p Two Pears 25p Three Bells 70p Two Bells 35p Three Bars £1 Two Bars 50p Three Double Bars £2 Two Double Bars £1 How I wrote the Slot Machine Version 1, The first version of the slot machine had eight different 32 by 30 active objects, one for each type of fruit. These objects were copied three times, one for each reel. A mask was then positioned over each of the reels, with a small area the size of the reel transparent, thus showing the fruit objects underneath. To determine a winning sequence was very simple. For example, for a line of cherries the following would be used: if number of "cherries" in zone (bar) = 3 then win situation Although this gave maximum control over the fruit movement the large number of masked objects caused the slot machine to run too slowly. Instead... Version 2, The solution was to replace the 24 fruit objects and three large mask objects with three smaller objects. This was achieved by pre-calculating all the possible reel positions. Having eight fruits, each 32 pixels high, gives a total reel size of 256 pixels. Active objects can have 32 different direction frames, which means that to display the whole reel each fruit must move 8 pixels at a time. (256 pixels / 32 frames = 8 pixels/frame.) Once the reel frames have been generated a reel can be spun by simply repeatedly incrementing the direction: "Fruits #1": set direction dir("Fruits #1") + 1. Having a single combination of fruits would result in a very predictable slot machine, so to add variety two additional reel fruit combinations were created. See objects "Fruits #1", "Fruits #2", and "Fruits #3". Each reel can be one of "Fruits #1", "Fruits #2" or "Fruits #3". Next, winning sequences need to be determined. This is considerably more difficult. If reel 1 is "Fruits #1" and direction is Cherries AND reel 2 is "Fruits #1" and direction is Cherries AND reel 3 is "Fruits #1" and direction is Cherries then WIN If reel 1 is "Fruits #2" and direction is Cherries AND reel 2 is "Fruits #1" and direction is Cherries AND reel 3 is "Fruits #1" and direction is Cherries then WIN If reel 1 is "Fruits #3" and direction is Cherries AND reel 2 is "Fruits #1" and direction is Cherries AND reel 3 is "Fruits #1" and direction is Cherries then WIN etc.. (for all combinations of Fruits #1, 2 and 3 and for all directions) Or more efficiently... A fruit is fully visible every four direction frames (each fruit is 32 pixels high and moves 8 pixels at a time). Therefore a variable (reel alterable value A) is set to the direction divided by 4, resulting in a value 0 to 7. To decode the fruits a “pseudo array” is created with active objects off-screen like this: Double bar Bar Cherries Bar Pear Bar Plum Double bar Double bar Lemon Lemon Bell Pear Plum Melon Melon Cherries Lemon Bell Bell Plum Cherries Melon Pear which represents the following array: Direction Fruits #1 Fruits #2 Fruits #3 0 Double bar Bar Cherries 1 Bar Pear Bar 2 Plum Double bar Double bar 3 Lemon Lemon Bell 4 Pear Plum Melon 5 Melon Cherries Lemon 6 Bell Bell Plum 7 Cherries Melon Pear Next there are three active objects "Reel Score #1", "Reel Score #2" and "Reel Score #3" which act a pseudo array indexes. The horizontal position of each "Reel Score" is determined by the type of fruit for each reel. To decode the reel the vertical position of the Reel Score is moved according to the direction (a value between 0 and 7). The resulting collision between the “Reel Score” and the “fruit” is stored in an alterable value according to the fruit. For example: On starting the game if reel 2 used "Fruits #2" then "Reel Score #1" would be horizontally positioned above the second column. Then during the game if the reel stopped on the melon, a direction value of 5, "Reel Score #1" would be positioned vertically at 160, 5 * 32. The resulting collision with the "Melon" would set "Reel Score #1" alterable value A to 999. Finally to determine a win the alterable value A of "Reel Score #1", "Reel Score #2" and "Reel Score #3" need to be checked for equality. if "Reel Score #1" A is 10 and "Reel Score #2" A is 10 and "Reel Score #3" A is 10 then WIN if "Reel Score #1" A is 20 and "Reel Score #2" A is 20 and "Reel Score #3" A is 20 then WIN RichardG.